class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end(), [](const vector<int>& x, const vector<int>& y) {return x[0] < y[0]; });
        int ans = 0;
        for (int i = 1; i < intervals.size(); ++i)
        {
            if (intervals[i][0] < intervals[i - 1][1])
            {
                ++ans;
                intervals[i][1] = min(intervals[i][1], intervals[i - 1][1]);
            }
        }
        return ans;
    }
};